#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPainter>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setWindowTitle("2D paint");
    tweight=700;
    theight=420;
    image = QImage(tweight,theight,QImage::Format_RGB32);
    QColor backColor = qRgb(0,255,255);
    image.fill(backColor);
    broad();
}

//void MainWindow::paintEvent(QPaintEvent *)
//{
//    QPainter painter(this);
//    painter.drawImage(0,0,image);
//}
void MainWindow::broad()
{
    QPainter painter(&image);

    painter.setRenderHint(QPainter::Antialiasing, true);
    int pointx=80;  //初始位置
    int pointy=80;
    int width=400;
    int height=250;
    painter.setBrush(Qt::white);
    painter.drawRect(50,50,500,300);
    painter.drawLine(pointx,pointy,width+pointx,pointy);
    painter.drawLine(pointx,pointy+height,pointx+width,pointy+height);
    painter.drawLine(pointx,pointy,pointx,pointy+height);
    painter.drawLine(pointx+width,pointy,pointx+width,pointy+height);
}

MainWindow::~MainWindow()
{
    delete ui;
}
